package cn.seocoo.platform.jpush;

import cn.seocoo.platform.common.utils.jpush.JpushUtil;
import cn.seocoo.platform.common.utils.jpush.MessageStatusEnum;
import cn.seocoo.platform.common.utils.jpush.MessageTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@EnableAsync
public class JpushMessageCommon {
    //private static MessagesMapper messagesMapper;

    //@Autowired
    /*public JpushMessageCommon(MessagesMapper messagesMapper) {
        JpushMessageCommon.messagesMapper = messagesMapper;
    }*/

    /**jpush极光推送 */
    public static String jpushAppKey;
    @Value("${jpush.appKey}")
    public void setJpushAppKey(String jpushAppKey) {
        JpushMessageCommon.jpushAppKey = jpushAppKey;
    }

    public static String jpushSecret;
    @Value("${jpush.masterSecret}")
    public void setJpushSecret(String jpushSecret) {
        JpushMessageCommon.jpushSecret = jpushSecret;
    }


    /**
     * 异步推送消息公共方法：推送极光消息并存入数据库
     *
     * @param userCode 用户编号
     * @param title    消息标题
     * @param content  消息内容
     * @param msgType  消息类型(0-其他消息;1-招聘消息)
     * @param remark   备注
     * @author duanpj
     * @date: 2019/9/3 14:28
     */
    @Async
    public void pushMessages(String userCode, String title, String content, String msgType, String remark) {
        //极光推送指定用户
        /*JpushUtil.sendOrderMessage(jpushAppKey, jpushSecret, userCode, content, title,
                content, MessageStatusEnum.INCOME_SUCCESS, MessageTypeEnum.ORDER);*/
        //极光推送全部
        /*JpushUtil.sendPushAll(jpushAppKey, jpushSecret, title, content);
        Messages msg = new Messages();
        msg.setUserCode(userCode);
        msg.setTitle(title);
        msg.setContent(content);
        msg.setCreateTime(new Date());
        msg.setMessageType(msgType);
        msg.setDelFlag("0");
        msg.setRemark(remark);
        messagesMapper.insertMessages(msg);*/
    }

    /**
     * 异步推送消息公共方法：循环推送极光消息给用户List并存入数据库
     *
     * @param userList
     * @param title
     * @param content
     * @param msgType
     * @param remark
     * @author duanpj
     * @date: 2019/11/5 18:55
     */
    @Async
    public void pushRecruit(List<Map> userList, String title, String content, String msgType, String remark) {
        //极光推送指定用户
       /* for (Map user : userList) {
            *//*JpushUtil.sendOrderMessage(jpushAppKey, jpushSecret, user.get("userCode").toString(), content, title,
                    content, MessageStatusEnum.INCOME_SUCCESS, MessageTypeEnum.ORDER);*//*
            Messages msg = new Messages();
            msg.setUserCode(user.get("userCode").toString());
            msg.setTitle(title);
            msg.setContent(content);
            msg.setCreateTime(new Date());
            msg.setMessageType(msgType);
            msg.setDelFlag("0");
            msg.setRemark(remark);
            messagesMapper.insertMessages(msg);
        }*/
    }
}
